package com.lill.sale.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lill.common.component.util.IdUtil;
import com.lill.product.service.IProductDiscountService;
import com.lill.sale.dao.IDiscountOfSaleDao;
import com.lill.sale.service.IDiscountOfSaleService;

/**
 * 车辆返利值Service实现类
 *
 * @author lill
 * @date 2021-09-06 20:23:17
 */
@Service("com.lill.sale.service.impl.DiscountOfSaleServiceImpl")
public class DiscountOfSaleServiceImpl implements IDiscountOfSaleService {
	
    @Autowired
    private IDiscountOfSaleDao discountOfSaleDao;
    @Autowired
    private IProductDiscountService productDiscountService;

    public Map<String, Object> queryObject(String id,String productCarId) {
    	Map<String, Object> discountMap=discountOfSaleDao.queryObject(id);
    	if(null==discountMap){
    		discountMap=productDiscountService.queryObject(productCarId);
    		discountMap.remove("product_id");
    		discountMap.remove("productId");
    	}
    	discountMap.put("saleCarId", id);
        return discountMap;
    }

    public int save(Map<String, Object> discountMap) {
    	int num=discountOfSaleDao.queryTotal(discountMap);
    	if(discountMap.containsKey("saleCarId")){
    		discountMap.put("sale_car_id", discountMap.get("saleCarId"));
    		discountMap.remove("saleCarId");
    	}
    	if(num>0){
    		return discountOfSaleDao.update(discountMap);
    	}else{
    		discountMap.put("id", IdUtil.createIdbyUUID());
    		return discountOfSaleDao.save(discountMap);
    	}
    }

}
